<%--
   Dict Selector
   Copyright (c) 2013 ISPERP
   Version : 1.0.0
 --%>
<%@tag import="org.apache.commons.lang3.StringUtils"%>
<%@tag import="itsm.isperp.module.entity.app.AppDict"%>
<%@tag import="java.util.List"%>
<%@tag import="itsm.isperp.framework.core.context.ContextHolder"%>
<%@tag import="itsm.isperp.module.service.app.AppDictService"%>
<%@ tag language="java" pageEncoding="UTF-8"
	deferredSyntaxAllowedAsLiteral="false" trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ attribute name="id" required="true" type="java.lang.String"
	description="唯一标识."%>
<%@ attribute name="name" required="false" type="java.lang.String"
	description="name"%>
<%@ attribute name="typeCode" required="true" type="java.lang.String"
	description="typeCode"%>
<%@ attribute name="type" required="false" type="java.lang.String"
	description="select,checkbox,reaio"%>
<%@ attribute name="codeValue" required="false" type="java.lang.Boolean"
	description="Boolean"%>
<%@ attribute name="selectedValue" required="false"
	type="java.lang.String" description="selectedValue"%>
<%@ attribute name="field" required="false" type="java.lang.String"
	description="field"%>
<%@ attribute name="op" required="false" type="java.lang.String"
	description="op"%>
<%@ attribute name="dictCssClass" required="false"
	type="java.lang.String" description="dictCssClass"%>
<%@ attribute name="dataWidth" required="false" type="java.lang.String"
	description="dataWidth"%>
<%@ attribute name="onchangeFunc" required="false"
	type="java.lang.String" description="onchangeFunc"%>
<%@ attribute name="hasEmptyValue" required="false"
	type="java.lang.Boolean" description="hasEmptyValue"%>
<%@ attribute name="checkAll" required="false"
	type="java.lang.Boolean" description="checkbox 选中所有"%>

<%@ attribute name="multiple" required="false"
	type="java.lang.Boolean" description="select multiple"%>
	
<c:set var="dataWidth" value="${empty dataWidth?'155px':dataWidth }"></c:set>


<jsp:doBody />
<%
	AppDictService appDictService = ContextHolder
			.getSpringBean("appDictService");

	List<AppDict> dicts = appDictService.findByType(typeCode);

	if (type == null || "select".equals(type)) {
%>
<select id="${id }" data-width="${dataWidth }" class="${dictCssClass }"
	name="${name }" field="${field }" op="${op }"
	onchange="${onchangeFunc }" ${multiple eq true?'multiple':''}>
	<%
		if (hasEmptyValue == null || hasEmptyValue) {
	%>
	<option value=""></option>
	<%
		}
	
		for (AppDict dict : dicts) {
			String dictValue = null;
			if (codeValue != null && codeValue == true) {
				dictValue = dict.getCode();
			} else {
				dictValue = dict.getName();
			}
	%>
	
	<option value="<%=dictValue%>" data-code="<%=dict.getCode()%>"
		<%if (dictValue.equals(selectedValue)) {%> selected="selected" <%}%>><%=dict.getName()%></option>
	<%
		}
	%>
</select>
<%
	} else {
%>
<%
	for (int iii = 0; iii < dicts.size(); iii++) {
			AppDict dict = dicts.get(iii);
			String dictValue = null;
			if (codeValue != null && codeValue == true) {
				dictValue = dict.getCode();
			} else {
				dictValue = dict.getName();
			}
%>
<input id="c_<%=dict.getId() %>" type="${type }" name="${name }"
	field="${field }" op="${op }" value="<%=dictValue%>"
	data-code="<%=dict.getCode()%>"
	<%if ( dictValue.equals(selectedValue)||(checkAll!=null&&checkAll== true)  ) {%> checked="checked" <%}%>>
<label for="c_<%=dict.getId()%>"><%=dict.getName()%></label>
<%
	}
	}
%>